package com.itheima.sh.user.controller;
import com.itheima.sh.user.pojo.User;
import com.itheima.sh.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")  //  /user/itcast
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") String username, HttpServletRequest request) {
        System.out.println("请求头==>" + request.getHeader("name"));
        return userService.queryById(username);
    }
    @PostMapping
    public String save(@RequestBody User user) {
        log.info("添加方法被调用==>"+user);
        return "success";
    }
}